package com.yloveg.common;

import java.util.HashMap;
import java.util.Map;

import org.springframework.ui.ModelMap;

import com.github.pagehelper.PageInfo;

public class PageUtil {
   
	/**
	 * layui分页工具
	 * @param pageList
	 * @return
	 */
   public static <T> Map<String,Object> dateToLayTable(PageInfo<T> pageList) {
	   Map<String,Object> resultMap = new HashMap<String, Object>();
	   if(pageList.getSize()>0){
		   resultMap.put("code", "0");
		   resultMap.put("msg", "查询成功！");
		   resultMap.put("count", pageList.getPages());
		   resultMap.put("data", pageList.getList());
	   }else{
		   resultMap.put("code", "1");
		   resultMap.put("msg", "还未有数据！");
	   }
	   return resultMap;
   }
   
   /**
    * freemark分页工具
    * @param map
    * @param pageList
    * @return
    */
   public static <T> ModelMap freemarkPage(ModelMap map,PageInfo<T> pageList){
	   map.put("pageNo", pageList.getPageNum());//当前页数
	   map.put("totalPage", pageList.getPages());//总页数
	   map.put("total", pageList.getPages());//总记录数
	   map.put("data", pageList.getList());//数据 
	   return map;
   }

}
